package com.community.web.user.controller.charge;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.community.common.login.LoginUserHolder;
import com.community.common.result.Result;
import com.community.model.entity.Charge;
import com.community.model.entity.ChargeDetail;
import com.community.web.user.service.ChargeDetailService;
import com.community.web.user.service.ChargeService;
import com.community.web.user.vo.ChargeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "物业费模块")
@RestController
@RequestMapping("/user/charge")
public class ChargeController {
    @Autowired
    private ChargeService service;

    @Autowired
    private ChargeDetailService detailService;

    @ApiOperation("根据用户id查询代缴纳物业费列表")
    @GetMapping()
    public Result<List<ChargeVo>> getChargeList(){
        Long userId = LoginUserHolder.getLoginUser().getUserId();
        List<ChargeVo> list = service.selectList(userId);
        return Result.ok(list);
    }

    @ApiOperation("根据物业费编号查询详情")
    @GetMapping("{chargeNo}")
    public Result<List<ChargeDetail>> getChargeDetail(@PathVariable String chargeNo){
        LambdaQueryWrapper<ChargeDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ChargeDetail::getChargeNo, chargeNo);
        List<ChargeDetail> list = detailService.list(queryWrapper);
        return Result.ok(list);
    }

    @ApiOperation("缴纳物业费")
    @PutMapping()
    public Result payment(@RequestBody List<Long> idList){
        Long userId = LoginUserHolder.getLoginUser().getUserId();
        service.payment(userId, idList);
        return Result.ok();
    }
}
